package persis

import (
	"go.mongodb.org/mongo-driver/bson/primitive"
	"math/rand"
	"my-gameserver-go/core/mynet/conn"
	"my-gameserver-go/logic/consts"
	"my-gameserver-go/proto/c2s"
)

type Player struct {
	OId              primitive.ObjectID `bson:"_id" json:"-"`
	PlayerId         int64
	PlayerName       string
	Conn             *conn.GameConnection `bson:"-"`
	RoutineChanIndex int32                `bson:"-"`
	ServerId         int32
}

func NewPlayer(msg *c2s.C2SLoginMessage) *Player {
	playerId := rand.Int63()
	return &Player{
		PlayerId:         playerId,
		PlayerName:       msg.UserName,
		RoutineChanIndex: int32(playerId % consts.PlayerRoutineNum),
	}
}

func (p *Player) GetObjId() primitive.ObjectID {
	return p.OId
}
